
package com.sgame.android.lang;

import com.sgame.android.data.TunnelTransmittable;
import java.util.*;
import java.util.Map.Entry;

import org.json.*;

public final class MapJsonObject
{

    public static String toString(String s, JSONObject jsonobject)
    {
        return (new StringBuilder()).append(s).append("Factory_delayed(").append(jsonobject.toString()).append(")").toString();
    }

    public static String toString(String s, Map<String,Object> map)
    {
        s = new String((new StringBuilder()).append(s).append("Factory_delayed({").toString());
        boolean flag = true;
        Iterator<Entry<String, Object>> iterator;
        for(iterator = map.entrySet().iterator(); iterator.hasNext();)
        {
            Object obj = (java.util.Map.Entry<String, Object>)iterator.next();
            if(flag)
                flag = false;
            else
                s = (new StringBuilder()).append(s).append(",").toString();
            s = (new StringBuilder()).append(s).append(JSONObject.quote((String)((java.util.Map.Entry<String, Object>) (obj)).getKey())).toString();
            s = (new StringBuilder()).append(s).append(":").toString();
            if((obj = ((java.util.Map.Entry<String, Object>) (obj)).getValue()) instanceof TunnelTransmittable)
                s = (new StringBuilder()).append(s).append(((TunnelTransmittable)obj).toJsonStringForTunnel()).toString();
            else
            if(obj instanceof JSONArray)
                s = (new StringBuilder()).append(s).append(obj.toString()).toString();
            else
                s = (new StringBuilder()).append(s).append(JSONObject.quote(obj != null ? obj.toString() : null)).toString();
        }

        return (new StringBuilder()).append(s).append("})").toString();
    }

    public static Map<String, String> createMap(JSONObject jsonobject, String s, String s1)
    {
    	int i;
		HashMap<String, String> hashmap = new HashMap<String, String>();
        JSONArray jsonarray = jsonobject.optJSONArray(s);
        JSONArray jsonarray1 = jsonobject.optJSONArray(s1);
        if(jsonarray != null && jsonarray1 != null && jsonarray.length() == jsonarray1.length())
        {
			try {
                for(i = 0; i < jsonarray.length(); i++)
					hashmap.put(jsonarray.getString(i), jsonarray1.getString(i));
			}
			catch (JSONException e) {
				throw new RuntimeException(e);
			}
        }
        else
            throw new RuntimeException((new StringBuilder("Array Pair ")).append(s).append(",").append(s1).append(" cannot be converted into a HashMap in json ").append(jsonobject).toString());
        return hashmap;
    }

    public static void a(Map<String, String> map, Map<String, JSONArray> map1, String s, String s1)
    {
        JSONArray jsonarray = new JSONArray();
        JSONArray jsonarray1 = new JSONArray();
        java.util.Map.Entry<String, String> entry;
        Iterator<Entry<String, String>> iterator;
        for(iterator = map.entrySet().iterator(); iterator.hasNext(); )
        {
            entry = (java.util.Map.Entry<String, String>)iterator.next();
            jsonarray.put(entry.getKey());
            jsonarray1.put(entry.getValue());
        }

        map1.put(s, jsonarray);
        map1.put(s1, jsonarray1);
    }
}
